﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Conventions;
using System.Data.Entity.Infrastructure;
using CodeFarmer.Model.Entities;
using CodeFarmer.Model.Mapping;

namespace CodeFarmer.DataAccess
{
    public class CodeFarmerContext : DbContext
    {
        private readonly static string CONNECTION_STRING = "name=CodeFarmerServer";
        
        static CodeFarmerContext()
        {
            Database.SetInitializer<CodeFarmerContext>(new CodeFarmerInitializer());
            //Database.SetInitializer<CodeFarmerContext>(null);
        }

        public CodeFarmerContext()
            : base(CONNECTION_STRING)
        {

        }

        public DbSet<User> User { get; set; }
        public DbSet<Article> Article { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
            //modelBuilder.Conventions.Remove<IncludeMetadataConvention>();

            modelBuilder.Configurations.Add(new UserMap());
            modelBuilder.Configurations.Add(new ArticleMap());
        }
    }
}
